{% load url from future %}
{% load icons %}
{% load query %}
{% load formats %}

<tr>
    {% if show_bulk %}
    <td class="column-checkbox"><input type="checkbox" name="select" value="{{ d.id }}"></td>
    {% endif %}
    <td class="column-name"><a
            href="{{ d.id|default:'' }}?{{ url_query.urlencode }}"
        >{%  for i in d.padding %}&nbsp;&nbsp;&nbsp;&nbsp;{%  endfor %}{{ d|device_icon }}&nbsp;{{ d.name|default:'unknown' }}
    </a>
    </td>
    {% if 'venture' in columns %}
    <td>
        {% if d.venture %}
            <a href="{% url 'ventures' d.venture.symbol details '' %}"
                >{{ d.venture.name }}</a>{% endif %}{% if d.venture_role %}/{{ d.venture_role.full_name }}{% endif %}
    </td>
    {% endif %}
    {% if 'service' in columns %}
        <td>
            {% if d.service %}
                <a href="{{ d.service.get_absolute_url }}">{{ d.service }}</a>
            {% else %}
                —
            {% endif %} /
            {% if d.device_environment %}
                <a href="{{ d.device_environment.get_absolute_url }}">{{ d.device_environment }}</a>
            {% else %}
                —
            {% endif %}
        </td>
    {% endif %}
    {% if 'model' in columns %}
    <td>{{ d.get_model_name }}</td>
    {% endif %}
    {% if 'margin' in columns %}
    <td>{{ d.get_margin|default:'0' }}%</td>
    {% endif %}
    {% if 'deprecation' in columns %}
    <td>{{ d.deprecation_kind|default:'' }}</td>
    {% endif %}
    {% if 'price' in columns %}
    <td class="currency">{{ d.cached_price|currency }}</td>
    {% endif %}
    {% if 'cost' in columns %}
        <td class="currency">
        {% if d.model.type == 204 %}
            —
        {% else %}
            {{d.cached_cost|currency }}
        {% endif %}
        {% if d.splunkusage_set.exists %}
            <i class="fugue-icon fugue-asterisk-small-yellow" title="nonpermanent costs" ></i>
        {% endif %}
        </td>
    {% endif %}
    {% if 'barcode' in columns %}
    <td>{{ d.barcode|default:'' }}</td>
    {% endif %}
    {% if 'serial_number' in columns %}
        <td>{{ d.sn|default:'' }}</td>
    {% endif %}
    {% if 'position' in columns %}
    <td>
        {% if d.dc %}<a href="{% url 'racks' "sn-"|add:d.dc|slugify details '' %}">{{ d.dc }}</a>/{% endif %}{% if d.rack %}<a href="{% url 'racks' "sn-"|add:d.rack|slugify details '' %}">{{ d.rack }}</a>/{% endif %}{% if d.parent and d.parent.model and d.parent.model.type == 2 %}{{ d.parent.chassis_position|default:'-' }}/{% endif %}{% if d.model.type == 203 %}{% if d.parent and d.parent.parent and d.parent.parent.model and d.parent.parent.model.type == 2 %}{{ d.parent.parent.get_position|default:'-' }}/{% endif %}{{ d.parent.get_position|default:'-' }}/{% endif %}<b>{{ d.get_position|default:'-' }}</b>
    </td>
    {% endif %}
    {% if 'ips' in columns %}
    <td class="column-ips">
        {% for ip in d.ipaddress_set.all %}
        {% if ip in network %}
            <b>{{ ip.address }}</b>
        {% else %}
            {{ ip.address }}
        {% endif %}
        {% endfor %}
    </td>
    {% endif %}
    {% if 'management' in columns %}
    {%  if d.management %}
    <td><a href="https://{{ d.management.address }}">{{ d.management.hostname|default:d.management.address }}</a></td>
    {%  else %}
    <td></td>
    {%  endif %}
    {% endif %}
    {% if 'created' in columns %}
    <td>{{ d.created|date:'Y-m-d H:i' }}</td>
    {% endif %}
    {% if 'lastseen' in columns %}
    <td>{{ d.last_seen|date:'Y-m-d H:i' }}</td>
    {% endif %}
    {% if 'lastping' in columns %}
    <td>{{ d.get_last_ping|date:'Y-m-d H:i'|default:'' }}</td>
    {% endif %}
    {% if 'reports' in columns %}
    <td>{%icon 'fugue-fingerprint'%}</td>
    {% endif %}
    {% if 'remarks' in columns %}
    <td class="column-remarks">{{ d.remarks }}</td>
    {% endif %}
    {% if 'purchase' in columns %}
    <td>{{ d.purchase_date|date:'Y-m-d H:i'|default:'' }}</td>
    {% endif %}
    {% if 'warranty' in columns %}
    <td>{{ d.warranty_expiration_date|date:'Y-m-d H:i'|default:'' }}</td>
    {% endif %}
    {% if 'support' in columns %}
    <td>{{ d.support_expiration_date|date:'Y-m-d H:i'|default:'' }}</td>
    {% endif %}
    {% if 'deprecation' in columns %}
    <td>
        {% if d.purchase_date %}
            {% if now > d.deprecation_date %}
                <i class="fugue-icon fugue-baggage-cart"></i> after deprecation
            {% else %}
                <i class="fugue-icon fugue-baggage-cart-box"></i> during deprecation
            {% endif %}
        {% elif d.model.type == device_types.cloud_server.id or d.model.type == device_types.virtual_server.id %}
        —
        {% else %}
            <i class="fugue-icon fugue-exclamation"></i> no purchase date
        {% endif %}
    </td>
    {% endif %}
</tr>
